home *** CD-ROM | disk | FTP | other *** search
- Path: ub239.dialup.uwa.edu.au!localhost!prye
- From: prye@cyllene.uwa.edu.au (Peter Rye)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with c code, please help!
- Date: 19 Jan 1996 18:02:50 GMT
- Organization: The University of Western Australia
- Message-ID: <PRYE.96Jan20020251@ub239.dialup.uwa.edu.au>
- References: <surgsw-1901960148530001@128.206.206.86>
- <mikedorman-1901960725380001@205.148.200.150>
- NNTP-Posting-Host: ub239.dialup.uwa.edu.au
- In-reply-to: mikedorman@cedarnet.com's message of Fri, 19 Jan 1996 07:25:37 -0600
-
-
- Hi Mike,
-
-
- > But, if you did it with a string pointer, it's this much easier:
- >
- > main()
- > {
- > char *word;
- >
- > puts("Enter a word: ");
- > while(scanf("%s", word) != 0)
- >
- > puts("You entered: ");
- > puts(word);
- > }
-
- I'm not sure that this is good advice.
-
- It gives a segmentation fault here, and/or goes into an infinite loop.
- Although it is ``easier'' to try to manage without allocating an array
- for your string, it will cause some problems when you try to stuff an
- arbitrary length string into a char * .
-
- scanf() will only return 0, and therefore exit the while loop when no
- assignments are made on input data.
-
- This ``advice'' comes to you from someone who made himself look a little
- foolish last week with some rubbish posted to the group, so take it with
- a large grain of salt :-).
-
- Regards,
- Peter Rye
- --
- | Peter Rye |
- | Respiratory Research Fellow |
- | Princess Margaret Hospital for Children |
- | Perth, Western Australia |
-